<?
include_once("config.php");
include_once(INC.'sess.php');

include_once(CLA."komand_log.class.php");
include_once(CLA."translate.class.php");
include_once(CLA."speech.class.php");
include_once(CLA."lucy_feelings.class.php");

$input_txt = $_POST['komand'];
$_SESSION['no_learning'] = $_POST['no_learning'];



$str = str_replace(" ", "+", $input_txt);
$komand = new Komand($str);

$translate = new Translate($komand->komand);
$translate->split();
$translate->get_mods();

if(is_array($translate->mods)){
	if(count($translate->mods) > 0){
		foreach($translate->mods AS $mod_name){
			if($mod_name != ''){
				$send = "<meta http-equiv='refresh' content=\"0;url=http://localhost/lucy/sys/mod/".$mod_name.".php?inSess=".session_id()."\">";
				echo $send;
			}
		}
	}else{
		$speech = new Speech;
		$speech->set_type($speech->get_type($str));

		if(is_word($str)){//		VĀRDS ZINĀMS  ->  RESPONSE
			
			$_SESSION['in']['word'] = $str;
			$_SESSION['options']['think'] = 0;
			$mod_name = "response";
			$send = "<meta http-equiv='refresh' content=\"0;url=http://localhost/lucy/sys/mod/".$mod_name.".php?inSess=".session_id()."\">";
			echo $send;
		
		}elseif($_SESSION['no_learning']){
			if(is_feeling($input_txt)){
				$_SESSION['type'] = "feeling";
				$_SESSION['feeling'] = str_replace(" ", "+", $input_txt);
			}
			
			if($speech->think_type($str, 1) != 0){
				$_SESSION['in']['word'] = $str;
				$_SESSION['options']['think'] = 1;
				$mod_name = "response";
				$send = "<meta http-equiv='refresh' content=\"0;url=http://localhost/lucy/sys/mod/".$mod_name.".php?inSess=".session_id()."\">";
				echo $send;
				die();
			}
			
			$_SESSION['in']['word'] = $str;
			$mod_name = "new_word";
			$send = "<meta http-equiv='refresh' content=\"0;url=http://localhost/lucy/sys/mod/".$mod_name.".php?inSess=".session_id()."\">";
			echo $send;	
		}else{
			$lucy_feeling = new Lucy_feelings();
			$lucy_feeling->change(-1);
			$_SESSION['print']['echo'] = "Tādu komandu \"$input_txt\" nezinu :(";
			$mod_name = "print";
			$send = "<meta http-equiv='refresh' content=\"0;url=http://localhost/lucy/sys/mod/".$mod_name.".php?inSess=".session_id()."\">";
			echo $send;
		}
	}
}
?>